/**
 * Created by qunxing.du on 2016/7/27.
 * Copyright 2016 汉威.智慧环保事业部 Limited.
 * All rights reserved.
 */
package com.hw.one.collect.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 *  hashcode工具类
 */
public class HashUtil {

    public synchronized static  int hashCode(String key){
        return key.hashCode();
    }

    /**
     * 郑州大气数据采集用
     * 通过传入参数获取hashcode
     * @param params
     * @return
     */
    public synchronized static int getHashCodeByParams(String params){
        String[] paramsArr = StringUtils.split(params, "&");
        int isSrc = -1, dataType = -1;
        String startTime = null ,endTime = null;
        for (String param : paramsArr) {
            String name = param.split("=")[0];
            String value = param.split("=")[1];
            if ("isSrc".equals(name)) {
                isSrc = NumberUtils.toInt(value);
                continue;
            }
            if ("dataType".equals(name)) {
                dataType = NumberUtils.toInt(value);
                continue;
            }
            if ("startTime".equals(name)) {
                startTime =value;
                continue;
            }
            if ("endTime".equals(name)) {
                endTime =value;
                continue;
            }
        }
        int key = hashCode(String.valueOf(isSrc)+String.valueOf(dataType)+startTime+endTime);
        return key;
    }
}
